<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>bfsNet: Fichero Fuente /Users/nicolunacba/Development/Dinic/trunk/bfs/bfs.c</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body onload='searchBox.OnSelectItem(0);'>
<!-- Generado por Doxygen 1.7.4 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'Buscar');
--></script>
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="bfs-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">bfsNet&#160;<span id="projectnumber">1.0</span></div>
   <div id="projectbrief">Algoritmo BFS para encontrar un camino de fuente a destino en una Network</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Página&#160;principal</span></a></li>
      <li><a href="annotated.html"><span>Estructuras&#160;de&#160;Datos</span></a></li>
      <li class="current"><a href="files.html"><span>Archivos</span></a></li>
      <li id="searchli">
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Buscar" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>Lista&#160;de&#160;archivos</span></a></li>
      <li><a href="globals.html"><span>Globales</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('bfs_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">/Users/nicolunacba/Development/Dinic/trunk/bfs/bfs.c</div>  </div>
</div>
<div class="contents">
<a href="bfs_8c.html">Ir a la documentación de este archivo.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> *  bfs.c</span>
<a name="l00003"></a>00003 <span class="comment"> *  </span>
<a name="l00004"></a>00004 <span class="comment"> *  Genera una BFS a partir de una Network y encuentra el camino</span>
<a name="l00005"></a>00005 <span class="comment"> *  de longitud minima al destino (trash) desde el origen (source)</span>
<a name="l00006"></a>00006 <span class="comment"> *</span>
<a name="l00007"></a>00007 <span class="comment"> */</span>
<a name="l00008"></a>00008 
<a name="l00009"></a>00009 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00010"></a>00010 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00011"></a>00011 <span class="preprocessor">#include &quot;<a class="code" href="bfs_8h.html">bfs.h</a>&quot;</span>
<a name="l00012"></a>00012 <span class="preprocessor">#include &quot;../network/network.h&quot;</span>
<a name="l00013"></a>00013 <span class="preprocessor">#include &quot;../network/tuple.h&quot;</span>
<a name="l00014"></a>00014 
<a name="l00015"></a>00015 <span class="comment">/* En la posicion 0 del arreglo se guarda la cantidad de hijos del nodo */</span>
<a name="l00016"></a><a class="code" href="bfs_8c.html#a5abfca151ab0db98334eff163e9bfc99">00016</a> <span class="preprocessor">#define NUM_CHILDREN children[0]</span>
<a name="l00017"></a>00017 <span class="preprocessor"></span>
<a name="l00018"></a>00018 <span class="comment">/* Tipos booleanos */</span>
<a name="l00019"></a><a class="code" href="bfs_8c.html#aa93f0eb578d23995850d61f7d61c55c1">00019</a> <span class="preprocessor">#define FALSE 0</span>
<a name="l00020"></a><a class="code" href="bfs_8c.html#aa8cecfc5c5c054d2875c03e77b7be15d">00020</a> <span class="preprocessor"></span><span class="preprocessor">#define TRUE !FALSE</span>
<a name="l00021"></a>00021 <span class="preprocessor"></span>
<a name="l00023"></a><a class="code" href="structs_b_f_s.html">00023</a> <span class="keyword">struct </span><a class="code" href="structs_b_f_s.html">sBFS</a>
<a name="l00024"></a>00024 {
<a name="l00026"></a><a class="code" href="structs_b_f_s.html#a07852b120b06d9f9e9609d7db5fb07ae">00026</a>         <a class="code" href="node_8h.html#a2f03a3e2ce8013d3b71182d9cafca989">Node</a> *<a class="code" href="structs_b_f_s.html#a07852b120b06d9f9e9609d7db5fb07ae">nodes</a>;            
<a name="l00028"></a><a class="code" href="structs_b_f_s.html#aad726bd9bdfa39cd9124f4f577c7e148">00028</a>         <span class="keywordtype">long</span> <span class="keywordtype">int</span> *<a class="code" href="structs_b_f_s.html#aad726bd9bdfa39cd9124f4f577c7e148">nodes_fathers</a>;
<a name="l00030"></a><a class="code" href="structs_b_f_s.html#ae9f51f5758591221e7f66f863b4f30a7">00030</a>         <span class="keywordtype">long</span> <span class="keywordtype">int</span> <a class="code" href="structs_b_f_s.html#ae9f51f5758591221e7f66f863b4f30a7">size</a>;          
<a name="l00032"></a><a class="code" href="structs_b_f_s.html#a49851f7063bee202c7af28053fe04392">00032</a>         <span class="keywordtype">long</span> <span class="keywordtype">int</span> <a class="code" href="structs_b_f_s.html#a49851f7063bee202c7af28053fe04392">used</a>;
<a name="l00033"></a>00033 };
<a name="l00034"></a>00034 
<a name="l00035"></a>00035 <span class="keywordtype">long</span> <span class="keywordtype">int</span> <a class="code" href="bfs_8c.html#a92f79ea6cf036564eae0ccb0f554a90f">min</a> (<span class="keywordtype">long</span> <span class="keywordtype">int</span> a, <span class="keywordtype">long</span> <span class="keywordtype">int</span> b);
<a name="l00036"></a>00036 
<a name="l00042"></a><a class="code" href="bfs_8h.html#ae11c689d3046a1a1cce70d6eabfdb14e">00042</a> <span class="keywordtype">long</span> <span class="keywordtype">int</span>* <a class="code" href="bfs_8c.html#ae11c689d3046a1a1cce70d6eabfdb14e">BFS_minimum_path</a>(<a class="code" href="structs_network.html">Network</a> net)
<a name="l00043"></a>00043 {
<a name="l00044"></a>00044         <a class="code" href="structs_b_f_s.html">BFS</a> bfs;
<a name="l00045"></a>00045         <a class="code" href="node_8h.html#a2f03a3e2ce8013d3b71182d9cafca989">Node</a> current_node;
<a name="l00046"></a>00046     <a class="code" href="node_8h.html#a2f03a3e2ce8013d3b71182d9cafca989">Node</a> node_son;
<a name="l00047"></a>00047         <span class="keywordtype">long</span> <span class="keywordtype">int</span> current_node_index = 0;
<a name="l00048"></a>00048         <a class="code" href="node_8h.html#a2f03a3e2ce8013d3b71182d9cafca989">Node</a> *children = NULL;
<a name="l00049"></a>00049         <span class="keywordtype">long</span> <span class="keywordtype">int</span> i = 0;
<a name="l00050"></a>00050         <span class="keywordtype">long</span> <span class="keywordtype">int</span> j = 0;
<a name="l00051"></a>00051         <span class="keywordtype">long</span> <span class="keywordtype">int</span> *tmp_path = NULL;
<a name="l00052"></a>00052         <span class="keywordtype">long</span> <span class="keywordtype">int</span> *final_path = NULL;
<a name="l00053"></a>00053     <span class="keywordtype">long</span> <span class="keywordtype">int</span> flow = -1;
<a name="l00054"></a>00054         <span class="keywordtype">int</span> trash_found = <a class="code" href="bfs_8c.html#aa93f0eb578d23995850d61f7d61c55c1">FALSE</a>;
<a name="l00055"></a>00055         
<a name="l00056"></a>00056         <span class="comment">/* Inicializacion de la estructura BFS */</span>
<a name="l00057"></a>00057         bfs.<a class="code" href="structs_b_f_s.html#a07852b120b06d9f9e9609d7db5fb07ae">nodes</a> = (<a class="code" href="node_8h.html#a2f03a3e2ce8013d3b71182d9cafca989">Node</a> *) calloc (1, <span class="keyword">sizeof</span>(<a class="code" href="node_8h.html#a2f03a3e2ce8013d3b71182d9cafca989">Node</a>));
<a name="l00058"></a>00058         bfs.<a class="code" href="structs_b_f_s.html#aad726bd9bdfa39cd9124f4f577c7e148">nodes_fathers</a> = (<span class="keywordtype">long</span> <span class="keywordtype">int</span>*) calloc (1, <span class="keyword">sizeof</span>(<span class="keywordtype">long</span> <span class="keywordtype">int</span>));
<a name="l00059"></a>00059         bfs.<a class="code" href="structs_b_f_s.html#ae9f51f5758591221e7f66f863b4f30a7">size</a> = 1;
<a name="l00060"></a>00060         bfs.<a class="code" href="structs_b_f_s.html#a49851f7063bee202c7af28053fe04392">used</a> = 1;
<a name="l00061"></a>00061     <span class="comment">/* En caso de memoria insuficiente */</span>
<a name="l00062"></a>00062         <span class="keywordflow">if</span> (bfs.<a class="code" href="structs_b_f_s.html#a07852b120b06d9f9e9609d7db5fb07ae">nodes</a> == NULL || bfs.<a class="code" href="structs_b_f_s.html#aad726bd9bdfa39cd9124f4f577c7e148">nodes_fathers</a> == NULL)
<a name="l00063"></a>00063     {
<a name="l00064"></a>00064         printf(<span class="stringliteral">&quot;Memoria insuficiente&quot;</span>);
<a name="l00065"></a>00065                 exit (EXIT_FAILURE);
<a name="l00066"></a>00066     }
<a name="l00067"></a>00067     
<a name="l00068"></a>00068         <span class="comment">/* La raiz de la BFS es el nodo Source, obtener el nodo, y agregarlo</span>
<a name="l00069"></a>00069 <span class="comment">         * El algoritmo toma como punto de inicio este nodo</span>
<a name="l00070"></a>00070 <span class="comment">         */</span>
<a name="l00071"></a>00071         current_node = <a class="code" href="network_8h.html#ad523c11cc6c14336c2b130d626823826">network_source_node</a>(net);
<a name="l00072"></a>00072         bfs.<a class="code" href="structs_b_f_s.html#a07852b120b06d9f9e9609d7db5fb07ae">nodes</a>[current_node_index] = current_node;
<a name="l00073"></a>00073         
<a name="l00074"></a>00074         <span class="comment">/* Ciclo principal del algoritmo BFS</span>
<a name="l00075"></a>00075 <span class="comment">         * Cuando se haya agregado al nodo Trash termina el ciclo</span>
<a name="l00076"></a>00076 <span class="comment">         */</span>
<a name="l00077"></a>00077         <span class="keywordflow">while</span> (!trash_found)
<a name="l00078"></a>00078         {
<a name="l00079"></a>00079                 <span class="comment">/* Obtener los vecinos del nodo corriente */</span>
<a name="l00080"></a>00080                 children = <a class="code" href="network_8c.html#a7284c2b25118f29553d6ce6262f95a54">network_get_neighbours</a>(net, current_node);
<a name="l00081"></a>00081                 
<a name="l00082"></a>00082                 <span class="comment">/* Verificar si el tamano actual del arreglo BFS alcanza para agregar los nodos</span>
<a name="l00083"></a>00083 <span class="comment">                 * De no alcanzar, aumentar el arreglo</span>
<a name="l00084"></a>00084 <span class="comment">                 */</span>
<a name="l00085"></a>00085         <span class="keywordflow">if</span> (children != NULL &amp;&amp; current_node != <a class="code" href="network_8h.html#aa8dcbacbbdd7bd554c467d0bf07a456e">network_trash_node</a>(net)) 
<a name="l00086"></a>00086         {
<a name="l00087"></a>00087             <span class="keywordflow">if</span> (bfs.<a class="code" href="structs_b_f_s.html#ae9f51f5758591221e7f66f863b4f30a7">size</a> - bfs.<a class="code" href="structs_b_f_s.html#a49851f7063bee202c7af28053fe04392">used</a> &lt;= <a class="code" href="bfs_8c.html#a5abfca151ab0db98334eff163e9bfc99">NUM_CHILDREN</a>)
<a name="l00088"></a>00088             {
<a name="l00089"></a>00089                 bfs.<a class="code" href="structs_b_f_s.html#ae9f51f5758591221e7f66f863b4f30a7">size</a> += <a class="code" href="bfs_8c.html#a5abfca151ab0db98334eff163e9bfc99">NUM_CHILDREN</a>;
<a name="l00090"></a>00090                 bfs.<a class="code" href="structs_b_f_s.html#a07852b120b06d9f9e9609d7db5fb07ae">nodes</a> = (<a class="code" href="node_8h.html#a2f03a3e2ce8013d3b71182d9cafca989">Node</a> *) realloc (bfs.<a class="code" href="structs_b_f_s.html#a07852b120b06d9f9e9609d7db5fb07ae">nodes</a>, bfs.<a class="code" href="structs_b_f_s.html#ae9f51f5758591221e7f66f863b4f30a7">size</a> * <span class="keyword">sizeof</span>(<a class="code" href="node_8h.html#a2f03a3e2ce8013d3b71182d9cafca989">Node</a>));
<a name="l00091"></a>00091                 <span class="keywordflow">if</span>(bfs.<a class="code" href="structs_b_f_s.html#a07852b120b06d9f9e9609d7db5fb07ae">nodes</a> == NULL){
<a name="l00092"></a>00092                     printf(<span class="stringliteral">&quot;Memoria insuficiente\n&quot;</span>);
<a name="l00093"></a>00093                     exit(EXIT_FAILURE);
<a name="l00094"></a>00094                 }
<a name="l00095"></a>00095                 bfs.<a class="code" href="structs_b_f_s.html#aad726bd9bdfa39cd9124f4f577c7e148">nodes_fathers</a> = (<span class="keywordtype">long</span> <span class="keywordtype">int</span> *) realloc (bfs.<a class="code" href="structs_b_f_s.html#aad726bd9bdfa39cd9124f4f577c7e148">nodes_fathers</a>, bfs.<a class="code" href="structs_b_f_s.html#ae9f51f5758591221e7f66f863b4f30a7">size</a> * <span class="keyword">sizeof</span>(<span class="keywordtype">long</span> <span class="keywordtype">int</span>));
<a name="l00096"></a>00096                 <span class="keywordflow">if</span>(bfs.<a class="code" href="structs_b_f_s.html#a07852b120b06d9f9e9609d7db5fb07ae">nodes</a>==NULL){
<a name="l00097"></a>00097                     printf(<span class="stringliteral">&quot;Memoria insuficiente\n&quot;</span>);
<a name="l00098"></a>00098                     exit(EXIT_FAILURE);
<a name="l00099"></a>00099                 }
<a name="l00100"></a>00100             }
<a name="l00101"></a>00101             
<a name="l00102"></a>00102             <span class="comment">/* Agregar los hijos del nodo en el BFS */</span>
<a name="l00103"></a>00103             <span class="keywordflow">for</span> (i = 1; i &lt;= <a class="code" href="bfs_8c.html#a5abfca151ab0db98334eff163e9bfc99">NUM_CHILDREN</a>; i++)
<a name="l00104"></a>00104             {
<a name="l00105"></a>00105                 <span class="comment">/* Agregar el nodo en el primer arreglo BFS </span>
<a name="l00106"></a>00106 <span class="comment">                 * y guardar referencia de su padre en el segundo</span>
<a name="l00107"></a>00107 <span class="comment">                 */</span>
<a name="l00108"></a>00108                 
<a name="l00109"></a>00109                 bfs.<a class="code" href="structs_b_f_s.html#a07852b120b06d9f9e9609d7db5fb07ae">nodes</a>[bfs.<a class="code" href="structs_b_f_s.html#a49851f7063bee202c7af28053fe04392">used</a>] = children[i];
<a name="l00110"></a>00110                 bfs.<a class="code" href="structs_b_f_s.html#aad726bd9bdfa39cd9124f4f577c7e148">nodes_fathers</a>[bfs.<a class="code" href="structs_b_f_s.html#a49851f7063bee202c7af28053fe04392">used</a>] = current_node_index;
<a name="l00111"></a>00111                 
<a name="l00112"></a>00112                 <span class="keywordflow">if</span> (children[i] == <a class="code" href="network_8h.html#aa8dcbacbbdd7bd554c467d0bf07a456e">network_trash_node</a>(net))
<a name="l00113"></a>00113                 {
<a name="l00114"></a>00114                     current_node = <a class="code" href="network_8h.html#aa8dcbacbbdd7bd554c467d0bf07a456e">network_trash_node</a>(net);
<a name="l00115"></a>00115                     current_node_index = bfs.<a class="code" href="structs_b_f_s.html#a49851f7063bee202c7af28053fe04392">used</a>;
<a name="l00116"></a>00116                     trash_found = <a class="code" href="bfs_8c.html#aa8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;
<a name="l00117"></a>00117                     <span class="keywordflow">break</span>;
<a name="l00118"></a>00118                 }
<a name="l00119"></a>00119                 bfs.<a class="code" href="structs_b_f_s.html#a49851f7063bee202c7af28053fe04392">used</a>++;
<a name="l00120"></a>00120             }
<a name="l00121"></a>00121         }
<a name="l00122"></a>00122         <span class="keywordflow">else</span>
<a name="l00123"></a>00123         {
<a name="l00124"></a>00124             free(bfs.<a class="code" href="structs_b_f_s.html#a07852b120b06d9f9e9609d7db5fb07ae">nodes</a>);
<a name="l00125"></a>00125             free(bfs.<a class="code" href="structs_b_f_s.html#aad726bd9bdfa39cd9124f4f577c7e148">nodes_fathers</a>);
<a name="l00126"></a>00126             <span class="keywordflow">return</span> NULL;
<a name="l00127"></a>00127         }
<a name="l00128"></a>00128 
<a name="l00129"></a>00129         
<a name="l00130"></a>00130         <span class="comment">/* Desplazarse al siguiente elemento del BFS en caso de no encontrar el trash*/</span>
<a name="l00131"></a>00131         <span class="keywordflow">if</span> (!trash_found)
<a name="l00132"></a>00132         {
<a name="l00133"></a>00133             current_node_index++;
<a name="l00134"></a>00134             current_node = bfs.<a class="code" href="structs_b_f_s.html#a07852b120b06d9f9e9609d7db5fb07ae">nodes</a>[current_node_index];
<a name="l00135"></a>00135             free(children);
<a name="l00136"></a>00136         }
<a name="l00137"></a>00137     }
<a name="l00138"></a>00138         
<a name="l00139"></a>00139     
<a name="l00140"></a>00140     <span class="keywordflow">if</span> (current_node == <a class="code" href="network_8h.html#aa8dcbacbbdd7bd554c467d0bf07a456e">network_trash_node</a>(net))
<a name="l00141"></a>00141     {
<a name="l00142"></a>00142         <span class="comment">/* En el peor de los casos, la longitud del path sera igual al</span>
<a name="l00143"></a>00143 <span class="comment">         * tamano usado del BFS (este seria un BFS donde cada nodo tenga</span>
<a name="l00144"></a>00144 <span class="comment">         * un solo vecino y asi se llega al nodo Trash)</span>
<a name="l00145"></a>00145 <span class="comment">         */</span>
<a name="l00146"></a>00146         
<a name="l00147"></a>00147         tmp_path = calloc (bfs.<a class="code" href="structs_b_f_s.html#a49851f7063bee202c7af28053fe04392">used</a> + 1, <span class="keyword">sizeof</span>(<span class="keywordtype">long</span> <span class="keywordtype">int</span>));
<a name="l00148"></a>00148         tmp_path[0] = current_node;
<a name="l00149"></a>00149         
<a name="l00150"></a>00150         i = 1;
<a name="l00151"></a>00151         
<a name="l00152"></a>00152         node_son = current_node;
<a name="l00153"></a>00153         current_node_index = bfs.<a class="code" href="structs_b_f_s.html#aad726bd9bdfa39cd9124f4f577c7e148">nodes_fathers</a>[current_node_index];
<a name="l00154"></a>00154         current_node = bfs.<a class="code" href="structs_b_f_s.html#a07852b120b06d9f9e9609d7db5fb07ae">nodes</a>[current_node_index];
<a name="l00155"></a>00155         flow = <a class="code" href="network_8c.html#aa9c38ef77dcf1df779b81eaa7f9f91ce">network_get_capacity</a>(net, current_node, node_son);
<a name="l00156"></a>00156         tmp_path[i] = current_node;
<a name="l00157"></a>00157         
<a name="l00158"></a>00158         i++;
<a name="l00159"></a>00159         
<a name="l00160"></a>00160         <span class="keywordflow">while</span> (current_node != <a class="code" href="network_8h.html#ad523c11cc6c14336c2b130d626823826">network_source_node</a>(net))
<a name="l00161"></a>00161         {
<a name="l00162"></a>00162             node_son = current_node;
<a name="l00163"></a>00163             current_node_index = bfs.<a class="code" href="structs_b_f_s.html#aad726bd9bdfa39cd9124f4f577c7e148">nodes_fathers</a>[current_node_index];
<a name="l00164"></a>00164             current_node = bfs.<a class="code" href="structs_b_f_s.html#a07852b120b06d9f9e9609d7db5fb07ae">nodes</a>[current_node_index];
<a name="l00165"></a>00165             flow = <a class="code" href="bfs_8c.html#a92f79ea6cf036564eae0ccb0f554a90f">min</a>(flow, <a class="code" href="network_8c.html#aa9c38ef77dcf1df779b81eaa7f9f91ce">network_get_capacity</a>(net, current_node, node_son));
<a name="l00166"></a>00166             tmp_path[i] = current_node;
<a name="l00167"></a>00167             i++;
<a name="l00168"></a>00168         }
<a name="l00169"></a>00169 
<a name="l00170"></a>00170             <span class="comment">/* El arreglo tmp_path queda con espacios vacios al final</span>
<a name="l00171"></a>00171 <span class="comment">             * y en orden inverso.</span>
<a name="l00172"></a>00172 <span class="comment">             * Se crea otro arreglo final_path en el orden correcto y de</span>
<a name="l00173"></a>00173 <span class="comment">             * tamano adecuado</span>
<a name="l00174"></a>00174 <span class="comment">             */</span>
<a name="l00175"></a>00175         final_path = calloc (i + 2, <span class="keyword">sizeof</span>(<span class="keywordtype">long</span> <span class="keywordtype">int</span>));
<a name="l00176"></a>00176         final_path[0] = i;
<a name="l00177"></a>00177         final_path[1] = flow;
<a name="l00178"></a>00178                 <span class="keywordflow">for</span> (j = 2; j &lt;= i + 1; j++)
<a name="l00179"></a>00179                 {
<a name="l00180"></a>00180                         final_path[j] = tmp_path[i - j + 1];
<a name="l00181"></a>00181                 }
<a name="l00182"></a>00182         
<a name="l00183"></a>00183         }
<a name="l00184"></a>00184         
<a name="l00185"></a>00185         <span class="comment">/* Liberar la memoria */</span>
<a name="l00186"></a>00186         free(bfs.<a class="code" href="structs_b_f_s.html#a07852b120b06d9f9e9609d7db5fb07ae">nodes</a>);
<a name="l00187"></a>00187         free(bfs.<a class="code" href="structs_b_f_s.html#aad726bd9bdfa39cd9124f4f577c7e148">nodes_fathers</a>);
<a name="l00188"></a>00188     <span class="keywordflow">if</span> (children != NULL)
<a name="l00189"></a>00189         free(children);
<a name="l00190"></a>00190         free(tmp_path);
<a name="l00191"></a>00191             
<a name="l00192"></a>00192         <span class="keywordflow">return</span> final_path;
<a name="l00193"></a>00193 }
<a name="l00194"></a>00194 
<a name="l00195"></a>00195 
<a name="l00196"></a><a class="code" href="bfs_8c.html#a92f79ea6cf036564eae0ccb0f554a90f">00196</a> <span class="keywordtype">long</span> <span class="keywordtype">int</span> <a class="code" href="bfs_8c.html#a92f79ea6cf036564eae0ccb0f554a90f">min</a> (<span class="keywordtype">long</span> <span class="keywordtype">int</span> a, <span class="keywordtype">long</span> <span class="keywordtype">int</span> b)
<a name="l00197"></a>00197 {
<a name="l00198"></a>00198     <span class="keywordflow">if</span> (a &lt; b)
<a name="l00199"></a>00199     {
<a name="l00200"></a>00200         <span class="keywordflow">return</span> a;
<a name="l00201"></a>00201     }
<a name="l00202"></a>00202     <span class="keywordflow">else</span> 
<a name="l00203"></a>00203     {
<a name="l00204"></a>00204         <span class="keywordflow">return</span> b;
<a name="l00205"></a>00205     }
<a name="l00206"></a>00206 }
<a name="l00207"></a>00207 
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="bfs_8c.html">bfs.c</a>      </li>
      <li class="footer">Generado el Miércoles, 13 de Abril de 2011 20:34:14 para bfsNet por&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>Todo</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Estructuras de Datos</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Archivos</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Funciones</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>&apos;typedefs&apos;</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>&apos;defines&apos;</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


</body>
</html>
